//
//  CompanyVC.m
//  MyProject
//
//  Created by jiaming yan on 2018/3/6.
//  Copyright © 2018年 yanjiaming. All rights reserved.
//

#import "CompanyVC.h"
#import "HXTagsView.h"
#import "HXTagAttribute.h"
#import "InterviewExperienceTableViewCell.h"
#import "CompanyJobTableViewCell.h"

@interface CompanyVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (strong, nonatomic)  NSMutableArray *arrData;

@property (weak, nonatomic) IBOutlet UIButton *typeButton1;
@property (weak, nonatomic) IBOutlet UIView *typeLine1;
@property (weak, nonatomic) IBOutlet UIButton *typeButton2;
@property (weak, nonatomic) IBOutlet UIView *typeLine2;

@property (weak, nonatomic) IBOutlet UILabel *companyDetailLable;

@property (weak, nonatomic) IBOutlet HXTagsView *tagBackView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightOfTags;

@property (weak, nonatomic) IBOutlet UILabel *addressLabel;




@property (strong, nonatomic) IBOutlet UIView *topView;

@property (assign, nonatomic) NSInteger selectedType;
@property (weak, nonatomic) IBOutlet UIView *jobTypeBackView;
@property (weak, nonatomic) IBOutlet HXTagsView *jobTypeView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *jobTypeHeight;

@end

@implementation CompanyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden = YES;
    
   
    
    _tagBackView.completion = ^(NSArray *selectTags,NSInteger currentIndex) {
        NSLog(@"selectTags:%@ currentIndex:%ld",selectTags, (long)currentIndex);
    };
    _tagBackView.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    HXTagAttribute *model = [[HXTagAttribute alloc]init];
    model.borderWidth  = 0;
    model.borderColor  = kClearColor;
    model.cornerRadius  = 8;
    model.titleSize  = 11;
    model.textColor  = UIColorFromRGB(0x00BCCC);
    model.normalBackgroundColor  = UIColorFromRGB(0xE7F4F6);
    model.selectedBackgroundColor  = UIColorFromRGB(0xE7F4F6);
    model.tagSpace  = 15;
    
    _tagBackView.tagAttribute = model;
    
    HXTagCollectionViewFlowLayout *flowLayout = [[HXTagCollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.sectionInset = UIEdgeInsetsZero;
    flowLayout.itemSize = CGSizeMake(79,20);
    flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 10.0f, 10.0f);
    _tagBackView.layout = flowLayout;
    
    [_tagBackView reloadData];
    
    _tagBackView.tags = @[@"员工旅游",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处",@"五险一金",@"领导好相处"];
    
    [_tagBackView reloadData];
    CGFloat height = [HXTagsView getHeightWithTags:self.tagBackView.tags layout:flowLayout tagAttribute:self.tagBackView.tagAttribute width:kScreenWidth-30];
    self.heightOfTags.constant = height;
    
    
    
    
    [self loadJobTypeFlag];
    
    
    
    
    
    
    [self loadTabbleView];
}
-(void)loadJobTypeFlag{
    _jobTypeView.completion = ^(NSArray *selectTags,NSInteger currentIndex) {
        NSLog(@"selectTags:%@ currentIndex:%ld",selectTags, (long)currentIndex);
    };
    _jobTypeView.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    
    HXTagAttribute *model = [[HXTagAttribute alloc]init];
    model.borderWidth  = 0;
    model.borderColor  = kClearColor;
    model.cornerRadius  = 3;
    model.titleSize  = 12;
    model.textColor  = UIColorFromRGB(0x59696D);
    model.normalBackgroundColor  = UIColorFromRGB(0xffffff);
    model.selectedBackgroundColor  = UIColorFromRGB(0x42CDD9);
    model.tagSpace  = 15;
    model.keyColor = kRedColor;
    _jobTypeView.tagAttribute = model;
    
    
    
    HXTagCollectionViewFlowLayout *flowLayout = [[HXTagCollectionViewFlowLayout alloc] init];
    flowLayout.minimumInteritemSpacing = 10;
    flowLayout.minimumLineSpacing = 10;
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.sectionInset = UIEdgeInsetsZero;
    flowLayout.itemSize = CGSizeMake(79,32);
    flowLayout.sectionInset = UIEdgeInsetsMake(0.0f, 0.0f, 10.0f, 10.0f);
    _jobTypeView.layout = flowLayout;
    
    [_jobTypeView reloadData];
    
    _jobTypeView.tags = @[@"推荐",@"技术",@"产品",@"设计",@"供应链",@"运营",@"酒店管理",@"java中高级开发工程师"];
    
    [_jobTypeView reloadData];
    CGFloat height = [HXTagsView getHeightWithTags:self.jobTypeView.tags layout:flowLayout tagAttribute:self.jobTypeView.tagAttribute width:kScreenWidth-30];
    self.jobTypeHeight.constant = height;
}
/*
 方法描述:
 加载列表
 
 参数说明:
 参数说明
 
 返回结果:
 <#返回结果#>
 
 */
-(void)loadTabbleView{
    [self loadHeaderHeight];
    self.tableView.tableHeaderView = self.topView;
    [self.tableView registerNib:[UINib nibWithNibName:@"CompanyJobTableViewCell" bundle:nil] forCellReuseIdentifier:@"CompanyJobTableViewCell"];
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.estimatedRowHeight = 184.0f;
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
    }
}
-(void)loadHeaderHeight{
    self.topView.clipsToBounds = YES;
    if (self.selectedType == 2) {
        CGFloat height = 238 + self.jobTypeHeight.constant + 15;
        self.topView.frame = CGRectMake(0, 0, kScreenWidth, height);
    }else{
        [self.companyDetailLable sizeToFit];
        [self.addressLabel sizeToFit];
        CGFloat height = 482.5+ self.heightOfTags.constant  + self.companyDetailLable.mj_h + self.addressLabel.mj_h-18.5;
        self.topView.frame = CGRectMake(0, 0, kScreenWidth, height);
    }
    self.tableView.tableHeaderView = self.topView;
    [self.tableView reloadData];
}
- (IBAction)typeButtonClick:(UIButton *)sender {
    if (self.typeButton1 == sender) {
        [self.typeButton1 setTitleColor:UIColorFromRGB(0X00BCCC) forState:UIControlStateNormal];
        [self.typeButton2 setTitleColor:UIColorFromRGB(0X59696D) forState:UIControlStateNormal];
        self.typeLine1.hidden = NO;
        self.typeLine2.hidden = YES;
        self.jobTypeBackView.hidden = YES;
        self.selectedType = 1;
        self.arrData = @[];
        
    }else{
        self.selectedType = 2;
        self.arrData = @[@"",@"",@""];
        [self.typeButton2 setTitleColor:UIColorFromRGB(0X00BCCC) forState:UIControlStateNormal];
        [self.typeButton1 setTitleColor:UIColorFromRGB(0X59696D) forState:UIControlStateNormal];
        self.jobTypeBackView.hidden = NO;
        self.typeLine2.hidden = NO;
        self.typeLine1.hidden = YES;
    }
    [self loadHeaderHeight];
}

#pragma mark ------tableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.arrData.count;
}

//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//{
//    return 65;
//}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    static NSString *identifier = @"CompanyJobTableViewCell";
    CompanyJobTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    cell.selectionStyle =  UITableViewCellSelectionStyleNone;
    //    MessageModel *model = self.arrData[indexPath.row];
    //    cell.titleName.text = model.title;
//    if (indexPath.row == 5) {
//        cell.contentLabel.text = @"中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答";
//    }else{
//        cell.contentLabel.text = @"中英文都有,中英文混杂的题目,大多数是选择题,笔试完了之后,二面是介绍自己,然后是一些英文问答";
//    }
    return cell;
    
}


- (void )tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)companyDetailMoreClick:(UIButton *)sender {
    sender.selected = !sender.selected;
    if (sender.selected) {
        self.companyDetailLable.numberOfLines = 0;
    }else{
        self.companyDetailLable.numberOfLines = 3;
    }
}
- (IBAction)backButtonClick:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
